from django.db import models

from user.models import User
from utils.common_base_models import BaseModel


# Create your models here.

class CustomProject(BaseModel):
    """
    装修案例
    """
    userinfo = models.ForeignKey(verbose_name='用户', to=User, on_delete=models.DO_NOTHING, db_constraint=False,
                                 null=True, blank=True, related_name='cus_project_userinfo')
    # title = models.CharField(max_length=16, unique=True, verbose_name='名称')
    desc = models.TextField(verbose_name='介绍', null=True, blank=True)

    # watch_num = models.BigIntegerField(verbose_name='观看数量', default=865)
    # 优化表中只存储点赞数量，记录在另一个表中
    comment_num = models.BigIntegerField(verbose_name='评论数量', default=366)
    comment_up = models.BigIntegerField(verbose_name='点赞数量', default=999)

    class Meta:
        db_table = 'youzhu_CustomProject'
        verbose_name_plural = '照片表'


class CustomPhoto(BaseModel):
    """
    照片
    """
    # title = models.CharField(max_length=16, unique=True, verbose_name='名称')
    custom = models.ForeignKey(to='CustomProject', on_delete=models.CASCADE, null=True, blank=True,
                               verbose_name='用户产品', related_name='cpp_p',db_constraint=False)
    image = models.CharField(verbose_name='图片',max_length=255)
    qiniu_link = models.CharField(max_length=255, verbose_name='七牛云链接',default=' http://baidu.com')

    class Meta:
        db_table = 'youzhu_CustomPhoto'
        verbose_name_plural = '照片表'


class CustomComment(BaseModel):
    """评论表"""
    custom = models.ForeignKey(to='CustomProject', on_delete=models.CASCADE, null=True, blank=True,
                               verbose_name='用户产品', related_name='cc_p',db_constraint=False)

    comment = models.TextField(verbose_name='评论内容')

    userinfo = models.ForeignKey(verbose_name='用户', to=User, on_delete=models.DO_NOTHING, db_constraint=False,
                                 null=True, blank=True, related_name='cus_comment_userinfo')

    reply = models.ForeignKey(verbose_name='父评论', to='self', on_delete=models.DO_NOTHING, db_constraint=False,
                              null=True, blank=True, related_name='cus_comment_reply')

    depth = models.PositiveIntegerField(verbose_name='评论深度', default=1)

    # root = models.PositiveIntegerField(verbose_name='根id', null=True, blank=True)
    class Meta:
        db_table = 'youzhu_CustomComment'
        verbose_name_plural = '评论表'


class CustomUp(BaseModel):
    """点赞"""

    userinfo = models.ForeignKey(verbose_name='用户', to=User, on_delete=models.DO_NOTHING, db_constraint=False,
                                 null=True, blank=True, related_name='comment_userinfo')

    custom = models.ForeignKey(to='CustomProject', on_delete=models.CASCADE, null=True, blank=True,
                               verbose_name='装修案例', related_name='cu_cp',db_constraint=False)

    class Meta:
        db_table = 'youzhu_CustomUp'
        verbose_name_plural = '点赞表'
